package com.aitaoxue.palx.service;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;

public class LoginService extends Service {

	private AlarmManager mAlarmMgr;

	@Override
	public IBinder onBind(Intent arg0) {
		return null;
	}

	@Override
	public void onCreate() {
		super.onCreate();
		mAlarmMgr = (AlarmManager) getSystemService(ALARM_SERVICE);
		startRequestAlarm();
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
		cancelRequestAlarm();
	}

	private void startRequestAlarm() {
		cancelRequestAlarm();
		mAlarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+60*1000*20, 60*1000*20, getOperationIntent());
	}

	private void cancelRequestAlarm() {
		mAlarmMgr.cancel(getOperationIntent());
	}

	private PendingIntent getOperationIntent() {
		Intent intent = new Intent(this, AlarmReceiver.class);
		PendingIntent operation = PendingIntent.getBroadcast(this, 0, intent,
				PendingIntent.FLAG_UPDATE_CURRENT);
		return operation;
	}

}
